<?php
namespace App\Repositories\GameServer;

use App\Models\GameServer\Goods;

class GoodsRepository
{
    //获取所有商品
    public function getGoodsList()
    {
        return Goods::orderBy('order_id', 'desc')->orderBy('id', 'desc')->get();
    }

    public function getGoods($id)
    {
        return Goods::find($id);
    }

    public function addGoods($request)
    {
        $params = $request->all();
        $params['icon'] = '0001';
        $params['vip_score'] = 0;
        $params['gift_vip_score'] = 0;

        return Goods::create($params);
    }

    public function updateGoods($request, $id)
    {
        return Goods::find($id)->update($request->all());
    }

    public function deleteGoods($id)
    {
        return Goods::destroy($id);
    }

    public function destroyList($ids)
    {
        return Goods::destroy($ids);
    }

    public function goodsSum($type)
    {
        return Goods::where('enable', 1)->where('pay_way', $type)->count();
    }

    public function editStatus($id, $status)
    {
        $room = Goods::findOrFail($id);
        $room->enable = $status;

        $room->save();

        return true;
    }
}